﻿using EtityTest;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace YJ_Hall.Controllers
{
    [Route("yjh/[controller]/[action]")]
    [ApiController]
    public class BillFareController : ControllerBase
    {
        private ApiDbContext acontext;
        public BillFareController(ApiDbContext apiDbContext)
        {
            acontext = apiDbContext;
        }

        [HttpGet]
        public List<BillFare> Get()
        {
            return acontext.BillFares.ToList();
        }

        //public List<BillFare> Get([FromBody]string Cooker, [FromBody] string Taste, [FromBody] string Cuisine)
        //{
        //    List<BillFare> billFares = new List<BillFare>();
        //    if (!string.IsNullOrEmpty(Cooker))
        //    {
        //        billFares.Where(w => w.Cooker == Cooker).ToList();
        //    }
        //    if (!string.IsNullOrEmpty(Taste))
        //    {
        //        billFares.Where(w => w.Cooker == Taste).ToList();
        //    }
        //    if (!string.IsNullOrEmpty(Cuisine))
        //    {
        //        billFares.Where(w => w.Cooker == Cuisine).ToList();
        //    }
        //    return billFares;
        //}

        [HttpGet("Get")]
        /// <summary>
        /// 多序列查询
        /// </summary>
        /// <param name="cooker"></param>
        /// <param name="taste"></param>
        /// <param name="cuisine"></param>
        /// <returns></returns>
        /// [FromBody]只能有一个参数不能带动三个，换成[FromHeader] / [FromQuery] 
        public List<BillFare> Get([FromHeader] string cooker, [FromQuery] string taste, [FromHeader][FromBody] string cuisine)
        {
            IQueryable<BillFare> query = acontext.BillFares;
            if (!string.IsNullOrEmpty(cooker))
            {
                query.Where(w => w.Cooker == cooker);
            }
            if (!string.IsNullOrEmpty(taste))
            {
                query.Where(w => w.Cooker == taste);
            }
            if (!string.IsNullOrEmpty(cuisine))
            {
                query.Where(w => w.Cooker == cuisine);
            }
            return query.ToList();
        }

        [HttpGet("like{name}")]
        public List<BillFare> Getbill(string name)
        {
            List<BillFare> bill = new List<BillFare>();
            bill.Where(w => w.Cooker.Contains(name)).ToList();
            return bill;
        }
    }
}
